﻿//通过对象ID返回对象
function $get(str) {
  if (typeof str == 'string' && document.getElementById(str) != null) {
    return document.getElementById(str);
  }
  return false;
}

//属性赋值
function val(no, type) {
  if (0 == type) {
    var imgUrl = this.argArray[no][2];
    var disp = 'none';
  } else {
    var imgUrl = this.argArray[no][1];
    var disp = '';
  }

  if (1 == this.bgOrTextOrClass) {
    $get(this.argArray[no][0]).innerHTML = '<img src="' + imgUrl + '">';
  } else if (2 == this.bgOrTextOrClass) {
    $get(this.argArray[no][0]).className = imgUrl;
  } else if (0 == this.bgOrTextOrClass) {
    $get(this.argArray[no][0]).style.background = 'url(' + imgUrl + '")';
  }

  if (typeof($get(this.argArray[no][3])) == 'object') {
    $get(this.argArray[no][3]).style.display = disp;
  }
}

//事件触发操作
function doChg(no) {
  if (this.curNo == no) {
    return false;
  }
  this.val(this.curNo, 0);
  this.val(no, 1);
  this.curNo = no;
}

//属性初始化
function chgTaginit() {
  var now = new Date();

  for (var i = 0; i < this.len; i++) {
    this.val(i, 0);
    $get(this.argArray[i][0]).name = this.argArray[i][0] + i;
    $get(this.argArray[i][0]).style.cursor = 'pointer';
  }

  var curNo = now.getHours() % this.len;

  this.val(curNo, 1); //默认高亮
  this.curNo = curNo;
}

//创建类名
chgBg = function(arr, eventCode, bgOrTextOrClass) {
  //属性
  this.argArray = arr;
  this.eventCode = eventCode;
  this.len = this.argArray.length;
  this.curNo = '0';
  if(bgOrTextOrClass){
  	this.bgOrTextOrClass =bgOrTextOrClass; //0,背景，1,内容，2，class;
  } else {
  	this.bgOrTextOrClass = 1; //内容
  }
  
	
  //方法
  this.val = val;
  this.doChg = doChg;
  this.val = val;
  this.chgTaginit = chgTaginit;
}

//外部调用函数
function attEvt(chg) {
  for (var i = 0; i < chg.len; i++) {
    $get(chg.argArray[i][0]).onclick = function() {
      chg.doChg(this.name.charAt(this.name.length - 1))
    };
  }
}